# Maintainer: Balló György <ballogyor+arch at gmail dot com>

pkgname=pdfslicer
pkgver=1.8.8
pkgrel=2
pkgdesc='Simple application to extract, merge, rotate and reorder pages of PDF documents'
arch=('loong64' 'x86_64')
url='https://junrrein.github.io/pdfslicer/'
license=('GPL3')
depends=('gtkmm3' 'poppler' 'qpdf')
makedepends=('cmake' 'git' 'intltool' 'ninja')
_commit=c843e4b5bff170d920aaf36debd454d11ac6e03b  # tags/v1.8.8
source=("git+https://github.com/junrrein/pdfslicer.git#commit=$_commit"
        "git+https://github.com/ericniebler/range-v3.git"
        "git+https://github.com/Microsoft/GSL.git"
        "git+https://github.com/fmtlib/fmt.git"
        qpdf-11.diff
        catch2_fix.diff)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP')

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^v//;s/-/+/g'
}

prepare() {
  cd $pkgname
  git submodule init
  git submodule set-url third-party/range-v3 "$srcdir/range-v3"
  git submodule set-url third-party/GSL "$srcdir/GSL"
  git submodule set-url third-party/fmtlib "$srcdir/fmt"
  git submodule update

  patch -Np1 -i ../qpdf-11.diff
  # https://patch-diff.githubusercontent.com/raw/prusa3d/PrusaSlicer/pull/6518.patch
  patch -Np1 -i ../catch2_fix.diff
}

build() {
  cmake -S $pkgname -B build -G Ninja -DCMAKE_INSTALL_PREFIX='/usr'
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
  rm -r "$pkgdir"/usr/{include,lib}
}
